<template>
  <svg :class="svgClass" @click="$emit('click', $event)" v-if="type">
    <use :xlink:href="iconName"></use>
  </svg>
  <svg :class="svgClass" @click="$emit('click', $event)" v-else>
    <use :xlink:href="iconName"></use>
  </svg>
</template>

<script>
export default {
  name: 'svg-icon',
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String
    },
    type: {
      type: Boolean,
      default () {
        return true
      }
    }
  },
  computed: {
    iconName () {
      return `#icon-${this.iconClass}`
    },
    svgClass () {
      if (this.className) {
        return this.className
      } else {
        return 'svg-icon'
      }
    }
  }
}
</script>

<style scoped>
  .svg-icon {
    width: 1em;
    height: 1em;
    fill: currentColor;
    overflow: hidden;
  }
</style>
